package org.lk.util;

import lombok.Data;

import java.io.Serializable;

/**
 * @author: lk
 * @since: 1.0
 * 响应结果封装
 */
@Data
public class ResponseResult<T> implements Serializable {

    /**
     * 响应码
     */
    private Integer code;
    /**
     * 响应信息
     */
    private String msg;
    /**
     * 响应数据
     */
    private T data;

    private ResponseResult() {
    }

    private ResponseResult(Integer code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public static <T> ResponseResult<T> success() {
        return of(200, "处理成功", null);
    }

    public static <T> ResponseResult<T> success(T data) {
        return of(200, "处理成功", data);
    }


    public static <T> ResponseResult<T> success(String msg, T data) {
        return of(200, msg, data);
    }

    public static <T> ResponseResult<T> fail(String msg) {
        return of(500, msg, null);
    }

    public static <T> ResponseResult<T> fail(Integer code, String msg) {
        return of(code, msg, null);
    }

    public static <T> ResponseResult<T> of(Integer code, String message, T data) {
        return new ResponseResult<>(code, message, data);
    }


}
